• Projects
  • R Packages
  • Publications
  • Graduate Students
  • Links
  • Courses
    • Single-case regression analzes
  • Private blog

On this page

  • Hi Wolfgang and Michel, here is a simple example to show the differences between treatment and effect contrasts.
  • Example dataset
  • Descriptives
  • Contrasts

Treatment vs. effect contrasts

regression
statistics
contrasts
Author

Jürgen Wilbert

Published

May 17, 2023

Hi Wolfgang and Michel, here is a simple example to show the differences between treatment and effect contrasts.

Example dataset

Create a random dataset with criteria y, predictors x1, x2 and gender.

All variables are correlated.

set.seed(1234)
n <- 10000
gender <- rep(0:1, each = n/2)
y <- sample(0:10, n, replace = TRUE) + gender * sample(0:10, n, replace = TRUE)
x1 <- sample(0:10, n, replace = TRUE) + gender * y
x2 <- x1 + sample(0:10, n, replace = TRUE) + gender * y
inter <- x1 > median(x1) & x2 > median(x2) & gender == 1
y[inter] <- y[inter] + sample(0:10, sum(inter), replace = TRUE)

dat <- data.frame(y = y, x1 = x1, x2 = x2, gender = gender)

Descriptives

psych::corr.test(dat)
Call:psych::corr.test(x = dat)
Correlation matrix 
          y   x1   x2 gender
y      1.00 0.79 0.83   0.66
x1     0.79 1.00 0.94   0.74
x2     0.83 0.94 1.00   0.79
gender 0.66 0.74 0.79   1.00
Sample Size 
[1] 10000
Probability values (Entries above the diagonal are adjusted for multiple tests.) 
       y x1 x2 gender
y      0  0  0      0
x1     0  0  0      0
x2     0  0  0      0
gender 0  0  0      0

 To see confidence intervals of the correlations, print with the short=FALSE option
psych::describe(dat)
vars n mean sd median trimmed mad min max range skew kurtosis se
y 1 10000 9.5326 6.768879 8.0 9.012750 7.4130 0 30 30 0.6222269 -0.5002773 0.0676888
x1 2 10000 10.0063 6.672279 9.0 9.585875 7.4130 0 30 30 0.5162774 -0.5350028 0.0667228
x2 3 10000 19.9998 12.575874 16.0 19.046000 11.8608 0 58 58 0.5910003 -0.6639372 0.1257587
gender 4 10000 0.5000 0.500025 0.5 0.500000 0.7413 0 1 1 0.0000000 -2.0002000 0.0050003

Contrasts

The left part of the table is with gender as treatment contrast (0 vs. 1) and the right part with gender as effect contrast (-1 vs. 1)

# Gender has values 0 vs. 1 (treatment contrast)
fit1 <- lm(y ~ gender * x1 * x2, data = dat)

# Gender hast -1 vs. 1 (effect contrast)
dat$gender <- car::recode(dat$gender, "0 = -1; 1 = 1")

fit2 <- lm(y ~ gender * x1 * x2, data = dat)

sjPlot::tab_model(fit1, fit2, show.se = TRUE, show.ci = FALSE, col.order = c("est", "se", "std.est", "p"), digits = 4)
  y y
Predictors Estimates std. Error p Estimates std. Error p
(Intercept) 5.1849 0.1880 <0.001 -0.7110 0.1882 <0.001
gender -11.7920 0.3764 <0.001 -5.8960 0.1882 <0.001
x1 0.0226 0.0420 0.590 0.2945 0.0259 <0.001
x2 -0.0066 0.0239 0.781 0.2983 0.0144 <0.001
gender × x1 0.5438 0.0519 <0.001 0.2719 0.0259 <0.001
gender × x2 0.6098 0.0288 <0.001 0.3049 0.0144 <0.001
x1 × x2 -0.0026 0.0036 0.479 -0.0072 0.0018 <0.001
(gender × x1) × x2 -0.0093 0.0037 0.011 -0.0047 0.0018 0.011
Observations 10000 10000
R2 / R2 adjusted 0.747 / 0.747 0.747 / 0.747
 
Copyright 2023, Jürgen Wilbert